##### User configurable options #####

top_srcdir           = @top_srcdir@

CC                   = @CC@
CFLAGS               = @CFLAGS@
CLINKER              = @CLINKER@
MPI_CC               = @MPI_CC@
MPI_CFLAGS           = @MPI_CFLAGS@
MPI_CLINKER          = $(MPI_CC)
MPI_LIBS             = @MPI_LIBS@
CC_INCS              = -I. -I${top_srcdir}
LDFLAGS              = @LDFLAGS@
FLIBS                = @FLIBS@ @F77_OTHER_LIBS@

MPE_BUILD_FORTRAN2C  = @MPE_BUILD_FORTRAN2C@
F77                  = @F77@
FFLAGS               = @FFLAGS@
MPI_F77              = @MPI_F77@
MPI_FFLAGS           = @MPI_FFLAGS@

MPERUN               = @MPERUN@


### End User configurable options ###

SHELL                = @SHELL@
MAKE                 = @MAKE@
MV                   = @MV@
RM                   = @RM@
CP                   = @CPRP@

@VPATH@

srcdir        = @srcdir@

CC_FLAGS      = $(CC_INCS) $(CFLAGS) $(MPE_COPTS)
FC_FLAGS      =            $(FFLAGS) $(MPE_FOPTS)
CC_LDFLAGS    = $(LDFLAGS) $(CFLAGS) $(MPE_LDOPTS)
FC_LDFLAGS    = $(LDFLAGS) $(FFLAGS) $(MPE_LDOPTS)
# MPE include path, x_INCS, goes in front of MPI include path, MPI_xFLAGS,
# in case MPI include path is in MPI_xFLAGS containing old MPE include path.
MPICC_FLAGS   = $(CC_INCS) $(MPI_CFLAGS) $(MPE_COPTS)
MPIFC_FLAGS   =            $(MPI_FFLAGS) $(MPE_FOPTS)
MPICC_LDFLAGS = $(LDFLAGS) $(MPI_CFLAGS) $(MPE_LDOPTS)
MPIFC_LDFLAGS = $(LDFLAGS) $(MPI_FFLAGS) $(MPE_LDOPTS)

C_EXECS       = cross_cc@EXEEXT@
F2C_EXECS     = cross_f2c@EXEEXT@

.SUFFIXES: .c .f .@OBJEXT@ .p@OBJEXT@ @EXEEXT@

.f.@OBJEXT@:
	$(F77) $(FC_FLAGS) -c $<

.c.@OBJEXT@:
	$(CC) $(CC_FLAGS) -c $<

.f.p@OBJEXT@:
	$(MPI_F77) $(MPIFC_FLAGS) -c $<
	$(MV) $*.@OBJEXT@ $*.p@OBJEXT@

.c.p@OBJEXT@:
	$(MPI_CC) $(MPICC_FLAGS) -c $<
	$(MV) $*.@OBJEXT@ $*.p@OBJEXT@

default: $(C_EXECS)
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	      $(MAKE) $(F2C_EXECS) ; \
	  fi

run:
	@-echo "Running $(C_EXECS) to get C compiler features..."
	@-$(MPERUN) $(C_EXECS)
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	       echo "Running $(F2C_EXECS) to get Fortran to C features..." ; \
	       $(MPERUN) $(F2C_EXECS) ; \
	  fi
	@-if [ -x ./cross_env ] ; then \
	      echo "Setting C and Fortran Development variables..." ; \
	      ./cross_env ; \
	  fi
	

cross_cc@EXEEXT@: cross_cc.@OBJEXT@
	$(CLINKER) $(CC_LDFLAGS) -o $@ cross_cc.@OBJEXT@

cross_f2c@EXEEXT@: flogical.@OBJEXT@ cross_f2c.p@OBJEXT@
	$(CP) -f cross_f2c.p@OBJEXT@ mpe2tmp.@OBJEXT@
	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ \
	               mpe2tmp.@OBJEXT@ flogical.@OBJEXT@ $(FLIBS)
	@-$(RM) -f mpe2tmp.@OBJEXT@

clean:
	@-$(RM) -f *.@OBJEXT@ $(C_EXECS) $(F2C_EXECS) cross_spec.txt
